import java.util.*;

/**
 * Created by zhourh on 2018/5/22.
 */
public class JewlesAndStones {

    public static void main(String[] args) {
        System.out.println(new JewlesAndStones().numJewelsInStones("aA", "aAAbbbb"));
    }

    public int numJewelsInStones(String J, String S) {
        if (J == null || J.length() <= 0 || S == null || S.length() <= 0) {
            return 0;
        }
        char[] jewleTypes = J.toCharArray();
        char[] stones = S.toCharArray();

        Set<Character> jewleTypeSet = new HashSet<>();
        for (char jewleType : jewleTypes) {
            jewleTypeSet.add(jewleType);
        }

        int result = 0;

        for (char stone : stones) {
            if (jewleTypeSet.contains(stone)) {
                result++;
            }
        }

        return result;
    }
}
